package cn.edu.glut.user.service.impl;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.assertj.core.util.Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.glut.entity.Major;
import cn.edu.glut.user.repository.MajorRepository;
import cn.edu.glut.user.service.MajorService;
/**
 * 
 * @author Caizhfy
 * @version v.0.1
 * @createTime 2017年12月13日下午9:08:35
 * @email Caizhfy@163.com
 * @description
 *
 */
@Service
public class MajorServiceImpl implements MajorService{
	@Autowired
	private MajorRepository majorRepository;
	
	@Override
	public List<Major> findAll() {
		return majorRepository.findAll();
	}

	@Override
	public void delete(String id) {
		majorRepository.delete(id);
	}

	@Override
	@Transactional
	public int update(Major m) {
		Preconditions.checkNotNull(majorRepository.findOne(m.getId()),"该专业不存在");
		majorRepository.save(m);
		return 1;
	}

	@Override
	public Major findById(String id) {
		return majorRepository.findOne(id);
	}

	@Override
	public Page<Major> list(Pageable pageable) {
		return majorRepository.findAll(pageable);
	}

	@Override
	public int save(Major m) {
		majorRepository.save(m);
		if(!StringUtils.isEmpty(m.getId()))
			return 1;
		return 0;
	}
	
}
